package datastructure.recursion;

import java.util.Scanner;

public class TriangleNum {

	static int triangle(int n) {
		if(n ==1) {
			System.out.println("Returning 1 ");
			return 1;
		} else {
			int temp = n + triangle(n-1);
			System.out.println("Returning "+temp);
			return temp;
		}		
	}
	
	public static void main(String[] args) {

		System.out.println("Enter Number : ");
		Scanner in = new Scanner(System.in);
		String number = in.nextLine();
		in.close();
		
		int num = Integer.parseInt(number);
		int t = triangle(num);
		System.out.println("\nNext Number is "+t);
		

	} // end of main
	
} // end of class
